//
//  SearchViewController.m
//  iShop
//
//  Created by svp on 18/12/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SearchViewController.h"
#import "SearchResultViewController.h"
#import "ResourceLoader.h"
#import "TitleTextfieldCell.h"

@implementation SearchViewController

@synthesize tableView = _tableView;
@synthesize seachButton = _seachButton;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(void) viewDidLoad
{
	[super viewDidLoad];
	self.title = @"Search";
	self.navigationItem.rightBarButtonItem = _seachButton;
	UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
	backButton.title = @"Back";
	self.navigationItem.backBarButtonItem = backButton;
	[backButton release];
}

- (void)dealloc {
	NSLog(@"SearchViewController dealloc");
	[_tableView release];
	[_seachButton release];
    [super dealloc];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	TitleTextfieldCell* cell = (TitleTextfieldCell*)[tableView dequeueReusableCellWithIdentifier:@"TitleTextfieldCell"];
	if (!cell) {
		ResourceLoader *rc = [[[ResourceLoader alloc] initWithNibNamed:@"TitleTextfieldCell"] autorelease];
		cell = (TitleTextfieldCell*)rc.resource;
		cell.textField.text = @"";
		cell.textField.enabled = NO;
		cell.textField.textAlignment = UITextAlignmentRight;
	}
	switch (indexPath.row) {
		case 0:
			cell.titleLabel.text = @"Shop";
			break;
		case 1:
			cell.titleLabel.text = @"Group Category";
			break;
		case 2:
			cell.titleLabel.text = @"Category";
			break;
		case 3:
			cell.titleLabel.text = @"Brand";
			break;
		default:
			break;
	}
	return cell;
}

-(IBAction)openSearchResult:(id) sender
{
	SearchResultViewController *custom = [[SearchResultViewController alloc] initWithNibName:@"SearchResultViewController" bundle: nil];
	[self.navigationController pushViewController:custom animated:YES];
	[custom release];
}

-(IBAction) homePress:(id) sender
{
	//[self.parentViewController dismissModalViewControllerAnimated:YES];
	[self.parentViewController dismissModalViewControllerAnimated:NO];
}

@end
